package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebEquipmentscancodeServiceImpl implements WebEquipmentscancodeService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebEquipmentscancodeServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebEquipmentscancodeMapper webEquipmentscancodeMapper;


    @Override
    public WebEquipmentscancode create(WebEquipmentscancode item) {

         webEquipmentscancodeMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webEquipmentscancodeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebEquipmentscancode item) {

        return webEquipmentscancodeMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebEquipmentscancode get(Integer id) {
        return webEquipmentscancodeMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<WebEquipmentscancode> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,WebEquipmentscancode item){

        WebEquipmentscancodeExample  example = new WebEquipmentscancodeExample();
        WebEquipmentscancodeExample.Criteria criteria = example.createCriteria();
        if(item.getEquipmenttypekey() != null ){
            criteria.andEquipmenttypekeyEqualTo(item.getEquipmenttypekey());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getEquipmentcode() != null ){
            criteria.andEquipmentcodeEqualTo(item.getEquipmentcode());
        }
        if(item.getEquipmentcodetype() != null ){
            criteria.andEquipmentcodetypeEqualTo(item.getEquipmentcodetype());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebEquipmentscancode> list = this.webEquipmentscancodeMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public WebEquipmentscancode getBycode(String code, Integer type) {
        return this.webEquipmentscancodeMapper.getBycode(code,type);
    }

}
